﻿
using Irony.Compiler;

namespace IronLua.Ast {

	public class WhileStatement : Statement {

		readonly Expression condition;
		readonly BlockStatement body;

		public Expression Condition {
			get { return condition; }
		}

		public BlockStatement Body {
			get { return body; }
		}

		public BlockStatement Block { get; set; }

		public override LuaNodeType NodeType {
			get { return LuaNodeType.WhileStatement; }
		}

		public WhileStatement (CompilerContext context, NonTerminal nonTerminal, SourceLocation location, AstNodeList childNodes)
			: base (context, nonTerminal, location, childNodes)
		{
			condition = ChildNodes [1].ToExpression ();
			body = ChildNodes [3].To<BlockStatement> ();
		}

		public override void Accept (ILuaAstVisitor visitor)
		{
			visitor.VisitWhileStatement (this);
		}
	}
}
